<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<?php
echo '<!--[if lt IE 9]>' . $this->Html->script('jquery/jqplot/excanvas.min') . '<![endif]-->';
echo $this->Html->script('jquery/jqplot/jquery.jqplot.min');
echo $this->Html->script('jquery/jqplot/plugins/jqplot.barRenderer.min');
echo $this->Html->script('jquery/jqplot/plugins/jqplot.pieRenderer.min');
echo $this->Html->script('jquery/jqplot/plugins/jqplot.categoryAxisRenderer.min');
echo $this->Html->script('jquery/jqplot/plugins/jqplot.canvasTextRenderer.min');
echo $this->Html->script('jquery/jqplot/plugins/jqplot.canvasAxisTickRenderer.min');
echo $this->Html->css('/js/jquery/jqplot/jquery.jqplot.min');
?>
<script type="text/javascript">

    $(function() {
        $('.btn_convert-img').on('click', function(e) {
            e.preventDefault();

            var imgStr = $(this).parents('.accordion-inner').find('.jqplot-target').jqplotToImageStr({});
            var img = $('<img class="raw_image" />');
            img.attr('src', imgStr);
            $(this).parents('.accordion-inner').find('.jqplot-target').after(img);
            $(this).parents('.accordion-inner').find('.jqplot-target').remove();
            $(this).remove();
        });
    });

</script>
<div class="visitorvoices index row">
    <div class="span12">
        <div class="btn-group pull-right">
            <?php
            echo $this->Html->link('<i class="ico-table"></i> ' . __('Response List'), array('action' => 'responses', $visitorform['Visitorform']['id']), array('class' => 'btn btn-primary', 'escape' => false));
            ?>
        </div> 
        <h2><?php echo $this->Html->link($visitorform['Visitorform']['title'], array('controller' => 'visitorforms', 'action' => 'view', $visitorform['Visitorform']['id'])) . ': ' . __('Statistics'); ?> <small><?php echo String::insert(__n(':count Response', ':count Responses', $visitorform['Visitorform']['visitorvoice_count']), array('count' => $visitorform['Visitorform']['visitorvoice_count'])); ?></small></h2>

        <?php if ($visitorform['Visitorform']['visitorvoice_count']): ?>

            <div class="accordion" id="statsAccordion">
                <?php
                $i = 0;
                foreach ($viewData['Statistics'] as $id => $stats):
                    if (in_array($stats['Field']['type'], array('rating', 'slider', 'spinner', 'select', 'selectmultiple', 'radio', 'checkbox', 'checkboxmultiple', 'textshort', 'textlong')))
                    {
                        ?>
                        <div class="accordion-group">
                            <div class="accordion-heading">
                                <a class="accordion-toggle" data-toggle="collapse" href="#accordion_<?php echo $id; ?>">
                                    <?php
                                    echo isset($stats['Field']['position']) ? ('<span class="label">' . $stats['Field']['position'] . '</span> ') : '';
                                    echo $stats['Field']['title'];
                                    ?>
                                </a>
                            </div>
                            <div id="accordion_<?php echo $id; ?>" class="accordion-body collapse<?php echo $i == 0 ? ' in' : ''; ?>">
                                <div class="accordion-inner">
                                    <?php if (in_array($stats['Field']['type'], array('selectmultiple', 'checkboxmultiple'))): ?>
                                        <?php echo $this->element('statistics/chart', array('type' => 'bar', 'id' => $id, 'stats' => $stats, 'count' => $viewData['count'])); ?>
                                    <?php elseif (in_array($stats['Field']['type'], array('radio', 'select', 'checkbox'))): ?>
                                        <?php echo $this->element('statistics/chart', array('type' => 'pie', 'id' => $id, 'stats' => $stats, 'count' => $viewData['count'])); ?>
                                    <?php elseif (in_array($stats['Field']['type'], array('textshort', 'textlong'))): ?>
                                        <?php echo $this->element('statistics/textfrequencies', array('id' => $id, 'stats' => $stats, 'count' => $viewData['count'])); ?>
                                    <?php else: ?>
                                        <?php echo $this->element('statistics/descriptives', array('id' => $id, 'stats' => $stats, 'count' => $viewData['count'])); ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                        <?php
                        $i++;
                    }
                endforeach;
                ?>
            </div>      
        <?php else: ?>
            <div class="well">
                <?php echo __('No responses available'); ?>
            </div>
        <?php endif; ?>


    </div>
</div>
